package com.hmall.cart.listenew;

import com.hmall.cart.service.ICartService;
import com.hmall.common.utils.UserContext;
import com.rabbitmq.client.AMQP;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

import java.util.Collection;

/**
 * @author xmy
 * @version 1.0
 */
@Slf4j
@Component
public class DeleteStatusListener {
    @Autowired
    private ICartService iCartService;
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "cart.clear.queue",durable = "true"),
            exchange = @Exchange(name = "trade.topic"),
            key = "order.create"
    ))
    public void listenDeleteSuccess(Collection<Long> ids, @Header("userId")Long userId){
        log.info("监听到删除ids：{}和用户id：{}",ids,userId);
        UserContext.setUser(userId);
        iCartService.removeByItemIds(ids);
    }

}
